/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.staffs.student.autopilot.views;

import gnu.io.SerialPortEventListener;

import java.awt.Color;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

import org.apache.log4j.Logger;

import uk.ac.staffs.student.autopilot.SerialPortStatus;
import uk.ac.staffs.student.autopilot.packet.GpsPacket;
import uk.ac.staffs.student.autopilot.packet.RtfPacket;
import uk.ac.staffs.student.autopilot.packet.TelemetryAccelsPacket;
import uk.ac.staffs.student.autopilot.packet.TelemetryGyrosPacket;

/**
 * 
 * @author Peter
 */
public class APHciSwingPanel extends JPanel implements Observer {

    /**
     * Creates new form Autopilot_HCI
     */
    public static Logger logger = Logger
            .getLogger(SerialPortEventListener.class);
    private TelemetryGyrosPacket tgp;
    private TelemetryAccelsPacket tap;
    private GpsPacket gpsPkt;

    // private JFrame frame;

    public APHciSwingPanel() {
        // this.frame = frame;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        telemetryPanel = new javax.swing.JPanel();
        gyroPanel = new javax.swing.JPanel();
        gyroLabel = new javax.swing.JLabel();
        axisxTxtF = new javax.swing.JTextField();
        axisxLabel = new javax.swing.JLabel();
        axisyTxtF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        axiszTxtF = new javax.swing.JTextField();
        axiszLabel = new javax.swing.JLabel();
        gpsPanel = new javax.swing.JPanel();
        gpsLabel = new javax.swing.JLabel();
        longTxtF = new javax.swing.JTextField();
        latTxtF = new javax.swing.JTextField();
        altitudeTxtF = new javax.swing.JTextField();
        grdSpeedTxtF = new javax.swing.JTextField();
        grdCourseTxtF = new javax.swing.JTextField();
        gpsNumSatTxtF = new javax.swing.JTextField();
        gpsFixTxtF = new javax.swing.JTextField();
        gpsLongLabel = new javax.swing.JLabel();
        gpsLatLabel = new javax.swing.JLabel();
        gpsAltLabel = new javax.swing.JLabel();
        gpsGndSpeedLabel = new javax.swing.JLabel();
        gpsGndCourseLabel = new javax.swing.JLabel();
        gpsNumSatLabel = new javax.swing.JLabel();
        gpsFixLabel = new javax.swing.JLabel();
        gpsTimeTxtF = new javax.swing.JTextField();
        gpsTimeLabel = new javax.swing.JLabel();
        telemetryLabel = new javax.swing.JLabel();
        accelPanel = new javax.swing.JPanel();
        accelLabel = new javax.swing.JLabel();
        accelxTxtF = new javax.swing.JTextField();
        accelyTxtF = new javax.swing.JTextField();
        accelzTxtF = new javax.swing.JTextField();
        accelxLabel = new javax.swing.JLabel();
        accelyLabel = new javax.swing.JLabel();
        accelzLabel = new javax.swing.JLabel();
        controlPanel = new javax.swing.JPanel();
        controlLabel = new javax.swing.JLabel();
        rtfModePanel = new javax.swing.JPanel();
        rtfModeBtn = new javax.swing.JButton();
        rtfModeDataSentTxtF = new javax.swing.JTextField();
        rtfModeReqSentLabel = new javax.swing.JLabel();
        rtfModeDataRecievedTxtF = new javax.swing.JTextField();
        rtfModeReqRecievedLabel = new javax.swing.JLabel();
        mrModePanel = new javax.swing.JPanel();
        mrModeBtn = new javax.swing.JButton();
        mrModeReqSentLabel = new javax.swing.JLabel();
        mrModeDataSentTxtF = new javax.swing.JTextField();
        mrModeReqRecievedLabel = new javax.swing.JLabel();
        mrModeDataRecievedTxtF = new javax.swing.JTextField();
        smModePanel = new javax.swing.JPanel();
        msBtn = new javax.swing.JButton();
        msModeReqSentLabel = new javax.swing.JLabel();
        msModeDataSentTxtF = new javax.swing.JTextField();
        msModeReqRecievedLabel = new javax.swing.JLabel();
        msModeDataRecievedTxtF = new javax.swing.JTextField();
        lmPanel = new javax.swing.JPanel();
        lmModeReqSentLabel = new javax.swing.JLabel();
        lmModeDataSentTxtF = new javax.swing.JTextField();
        lmModeReqRecievedLabel = new javax.swing.JLabel();
        lmModeDataRecievedTxtF = new javax.swing.JTextField();
        lmBtn = new javax.swing.JButton();
        connectionsPanel = new javax.swing.JPanel();
        conLabel = new javax.swing.JLabel();
        serialPTxtF = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        baudTxtF = new javax.swing.JTextField();
        baudLabel = new javax.swing.JLabel();
        connectedTxtF = new javax.swing.JTextField();
        connectedLabel = new javax.swing.JLabel();
        exitBtn = new javax.swing.JButton();
        exitBtn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent arg0) {
                // Really should send a signal to the controller object here
                // Then clean up and close.
                System.exit(0);

            }
        });

        telemetryPanel
                .setBorder(javax.swing.BorderFactory.createEtchedBorder());

        gyroPanel.setBorder(javax.swing.BorderFactory
                .createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        gyroLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        gyroLabel.setText("Gyro Data");

        axisxTxtF.setText(" ");

        axisxLabel.setText("Axis X:");

        jLabel1.setText("Axis Y:");

        axiszLabel.setText("Axis Z:");

        final javax.swing.GroupLayout gyroPanelLayout = new javax.swing.GroupLayout(
                gyroPanel);
        gyroPanel.setLayout(gyroPanelLayout);
        gyroPanelLayout
                .setHorizontalGroup(gyroPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                gyroPanelLayout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(
                                                gyroPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(gyroLabel)
                                                        .addGroup(
                                                                gyroPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addGap(16,
                                                                                16,
                                                                                16)
                                                                        .addGroup(
                                                                                gyroPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                        .addComponent(
                                                                                                axisxLabel)
                                                                                        .addComponent(
                                                                                                jLabel1)
                                                                                        .addComponent(
                                                                                                axiszLabel))
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                        .addGroup(
                                                                                gyroPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                false)
                                                                                        .addComponent(
                                                                                                axisxTxtF,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                100,
                                                                                                Short.MAX_VALUE)
                                                                                        .addComponent(
                                                                                                axisyTxtF)
                                                                                        .addComponent(
                                                                                                axiszTxtF))))));
        gyroPanelLayout
                .setVerticalGroup(gyroPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                gyroPanelLayout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(gyroLabel)
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(
                                                gyroPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                axisxLabel)
                                                        .addComponent(
                                                                axisxTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                gyroPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(jLabel1)
                                                        .addComponent(
                                                                axisyTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                gyroPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                axiszLabel)
                                                        .addComponent(
                                                                axiszTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addContainerGap(16, Short.MAX_VALUE)));

        gpsPanel.setBorder(javax.swing.BorderFactory
                .createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        gpsLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        gpsLabel.setText("GPS Data");

        gpsLongLabel.setText("Longitude:");

        gpsLatLabel.setText("Latitude:");

        gpsAltLabel.setText("Altitude:");

        gpsGndSpeedLabel.setText("Ground Speed:");

        gpsGndCourseLabel.setText("Ground Course:");

        gpsNumSatLabel.setText("# Satelites:");

        gpsFixLabel.setText("Fix:");

        gpsTimeLabel.setText("Time:");

        final javax.swing.GroupLayout gpsPanelLayout = new javax.swing.GroupLayout(
                gpsPanel);
        gpsPanel.setLayout(gpsPanelLayout);
        gpsPanelLayout
                .setHorizontalGroup(gpsPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                gpsPanelLayout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(
                                                gpsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(
                                                                gpsPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addGroup(
                                                                                gpsPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                        .addGroup(
                                                                                                gpsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addGroup(
                                                                                                                gpsPanelLayout
                                                                                                                        .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                        .addGroup(
                                                                                                                                gpsPanelLayout
                                                                                                                                        .createSequentialGroup()
                                                                                                                                        .addComponent(
                                                                                                                                                gpsLatLabel,
                                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                Short.MAX_VALUE)
                                                                                                                                        .addGap(12,
                                                                                                                                                12,
                                                                                                                                                12))
                                                                                                                        .addComponent(
                                                                                                                                gpsLongLabel,
                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                Short.MAX_VALUE))
                                                                                                        .addPreferredGap(
                                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                        .addGroup(
                                                                                                                gpsPanelLayout
                                                                                                                        .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                        .addComponent(
                                                                                                                                latTxtF,
                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                109,
                                                                                                                                Short.MAX_VALUE)
                                                                                                                        .addComponent(
                                                                                                                                longTxtF,
                                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                109,
                                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                                        .addGroup(
                                                                                                gpsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addComponent(
                                                                                                                gpsAltLabel,
                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                54,
                                                                                                                Short.MAX_VALUE)
                                                                                                        .addGap(23,
                                                                                                                23,
                                                                                                                23)
                                                                                                        .addComponent(
                                                                                                                altitudeTxtF,
                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                109,
                                                                                                                Short.MAX_VALUE)))
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addGroup(
                                                                                gpsPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                        .addGroup(
                                                                                                gpsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addGroup(
                                                                                                                gpsPanelLayout
                                                                                                                        .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                        .addComponent(
                                                                                                                                gpsGndCourseLabel,
                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                Short.MAX_VALUE)
                                                                                                                        .addGroup(
                                                                                                                                gpsPanelLayout
                                                                                                                                        .createSequentialGroup()
                                                                                                                                        .addComponent(
                                                                                                                                                gpsNumSatLabel,
                                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                                Short.MAX_VALUE)
                                                                                                                                        .addGap(29,
                                                                                                                                                29,
                                                                                                                                                29)))
                                                                                                        .addPreferredGap(
                                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                        .addGroup(
                                                                                                                gpsPanelLayout
                                                                                                                        .createParallelGroup(
                                                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                                                        .addComponent(
                                                                                                                                gpsNumSatTxtF,
                                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                                94,
                                                                                                                                Short.MAX_VALUE)
                                                                                                                        .addComponent(
                                                                                                                                grdCourseTxtF,
                                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                                94,
                                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                                        .addGroup(
                                                                                                gpsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addComponent(
                                                                                                                gpsGndSpeedLabel,
                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                Short.MAX_VALUE)
                                                                                                        .addGap(18,
                                                                                                                18,
                                                                                                                18)
                                                                                                        .addComponent(
                                                                                                                grdSpeedTxtF,
                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                93,
                                                                                                                Short.MAX_VALUE)))
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addGroup(
                                                                                gpsPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                        .addGroup(
                                                                                                gpsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addComponent(
                                                                                                                gpsFixLabel,
                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                                Short.MAX_VALUE)
                                                                                                        .addGap(12,
                                                                                                                12,
                                                                                                                12))
                                                                                        .addComponent(
                                                                                                gpsTimeLabel,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                Short.MAX_VALUE))
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addGroup(
                                                                                gpsPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                        .addComponent(
                                                                                                gpsTimeTxtF,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                83,
                                                                                                Short.MAX_VALUE)
                                                                                        .addComponent(
                                                                                                gpsFixTxtF,
                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                83,
                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                        .addComponent(gpsLabel))
                                        .addContainerGap()));
        gpsPanelLayout
                .setVerticalGroup(gpsPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                gpsPanelLayout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(gpsLabel)
                                        .addGap(13, 13, 13)
                                        .addGroup(
                                                gpsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                gpsLongLabel)
                                                        .addComponent(
                                                                longTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                gpsGndSpeedLabel)
                                                        .addComponent(
                                                                grdSpeedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                gpsFixLabel)
                                                        .addComponent(
                                                                gpsFixTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                gpsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                gpsLatLabel)
                                                        .addComponent(
                                                                latTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                gpsGndCourseLabel)
                                                        .addComponent(
                                                                grdCourseTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                gpsTimeLabel)
                                                        .addComponent(
                                                                gpsTimeTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                gpsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                gpsAltLabel)
                                                        .addComponent(
                                                                altitudeTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                gpsNumSatLabel)
                                                        .addComponent(
                                                                gpsNumSatTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addContainerGap(
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)));

        telemetryLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        telemetryLabel.setText("Telemetry Data");

        accelPanel.setBorder(javax.swing.BorderFactory
                .createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        accelLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        accelLabel.setText("Accellerometer Data");

        accelxLabel.setText("Axis X:");

        accelyLabel.setText("Axis Y:");

        accelzLabel.setText("Axis Z:");

        final javax.swing.GroupLayout accelPanelLayout = new javax.swing.GroupLayout(
                accelPanel);
        accelPanel.setLayout(accelPanelLayout);
        accelPanelLayout
                .setHorizontalGroup(accelPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                accelPanelLayout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(
                                                accelPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                accelLabel)
                                                        .addGroup(
                                                                accelPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                accelxLabel)
                                                                        .addGap(18,
                                                                                18,
                                                                                18)
                                                                        .addComponent(
                                                                                accelxTxtF,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                102,
                                                                                Short.MAX_VALUE))
                                                        .addGroup(
                                                                accelPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                accelzLabel)
                                                                        .addGap(18,
                                                                                18,
                                                                                18)
                                                                        .addComponent(
                                                                                accelzTxtF,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                102,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addGroup(
                                                                accelPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                accelyLabel)
                                                                        .addGap(18,
                                                                                18,
                                                                                18)
                                                                        .addComponent(
                                                                                accelyTxtF,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                102,
                                                                                Short.MAX_VALUE)))
                                        .addContainerGap()));
        accelPanelLayout
                .setVerticalGroup(accelPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                accelPanelLayout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(accelLabel)
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(
                                                accelPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                accelxLabel)
                                                        .addComponent(
                                                                accelxTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                accelPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                accelyLabel)
                                                        .addComponent(
                                                                accelyTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)
                                        .addGroup(
                                                accelPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(
                                                                accelzLabel)
                                                        .addComponent(
                                                                accelzTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addContainerGap()));

        final javax.swing.GroupLayout telemetryPanelLayout = new javax.swing.GroupLayout(
                telemetryPanel);
        telemetryPanel.setLayout(telemetryPanelLayout);
        telemetryPanelLayout
                .setHorizontalGroup(telemetryPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                telemetryPanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                telemetryPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                telemetryLabel)
                                                        .addGroup(
                                                                telemetryPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addGap(11,
                                                                                11,
                                                                                11)
                                                                        .addComponent(
                                                                                gyroPanel,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                        .addComponent(
                                                                                accelPanel,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(18,
                                                                                18,
                                                                                18)
                                                                        .addComponent(
                                                                                gpsPanel,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addContainerGap(
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)));
        telemetryPanelLayout
                .setVerticalGroup(telemetryPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                telemetryPanelLayout
                                        .createSequentialGroup()
                                        .addComponent(telemetryLabel)
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                telemetryPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(gpsPanel,
                                                                0, 157,
                                                                Short.MAX_VALUE)
                                                        .addComponent(
                                                                accelPanel, 0,
                                                                157,
                                                                Short.MAX_VALUE)
                                                        .addComponent(
                                                                gyroPanel,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                157,
                                                                Short.MAX_VALUE))
                                        .addContainerGap(15, Short.MAX_VALUE)));

        controlPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        controlLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        controlLabel.setText("Control Panel");

        rtfModePanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        rtfModeBtn.setBackground(new java.awt.Color(255, 255, 0));
        rtfModeBtn.setText("Ready to Fly Mode");
        
        rtfModeBtn.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(final java.awt.event.ActionEvent evt) {
                rtfModeBtnActionPerformed(evt);
            }
        });

        rtfModeDataSentTxtF.setBackground(new java.awt.Color(255, 0, 0));
        rtfModeDataSentTxtF.setEnabled(false);
        rtfModeDataSentTxtF.setPreferredSize(new java.awt.Dimension(10, 20));
        rtfModeDataSentTxtF.setRequestFocusEnabled(false);

        rtfModeReqSentLabel.setText("Send:");

        rtfModeDataRecievedTxtF.setBackground(new java.awt.Color(255, 0, 0));
        rtfModeDataRecievedTxtF.setEnabled(false);
        rtfModeDataRecievedTxtF
                .setPreferredSize(new java.awt.Dimension(10, 20));

        rtfModeReqRecievedLabel.setText("Receive");

        final javax.swing.GroupLayout rtfModePanelLayout = new javax.swing.GroupLayout(
                rtfModePanel);
        rtfModePanel.setLayout(rtfModePanelLayout);
        rtfModePanelLayout
                .setHorizontalGroup(rtfModePanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                rtfModePanelLayout
                                        .createSequentialGroup()
                                        .addComponent(
                                                rtfModeBtn,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                149,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE))
                        .addGroup(
                                rtfModePanelLayout
                                        .createSequentialGroup()
                                        .addGap(46, 46, 46)
                                        .addGroup(
                                                rtfModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                rtfModeReqSentLabel)
                                                        .addComponent(
                                                                rtfModeReqRecievedLabel))
                                        .addGap(5, 5, 5)
                                        .addGroup(
                                                rtfModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                rtfModeDataRecievedTxtF,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                20,
                                                                Short.MAX_VALUE)
                                                        .addComponent(
                                                                rtfModeDataSentTxtF,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                20,
                                                                Short.MAX_VALUE))
                                        .addGap(46, 46, 46)));
        rtfModePanelLayout
                .setVerticalGroup(rtfModePanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                rtfModePanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                rtfModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                rtfModeReqSentLabel)
                                                        .addComponent(
                                                                rtfModeDataSentTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                rtfModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                rtfModeReqRecievedLabel)
                                                        .addComponent(
                                                                rtfModeDataRecievedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(rtfModeBtn)));

        mrModePanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        mrModeBtn.setBackground(new java.awt.Color(0, 255, 0));
        mrModeBtn.setText("Mission Ready Mode");
        mrModeBtn.setEnabled(true);
        mrModeBtn.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(final java.awt.event.ActionEvent evt) {
                mrModeBtnActionPerformed(evt);
            }
        });

        mrModeReqSentLabel.setText("Send:");

        mrModeDataSentTxtF.setBackground(new java.awt.Color(255, 0, 0));
        mrModeDataSentTxtF.setEnabled(false);
        mrModeDataSentTxtF.setPreferredSize(new java.awt.Dimension(10, 20));

        mrModeReqRecievedLabel.setText("Receive:");

        mrModeDataRecievedTxtF.setBackground(new java.awt.Color(255, 0, 0));
        mrModeDataRecievedTxtF.setEnabled(false);
        mrModeDataRecievedTxtF.setPreferredSize(new java.awt.Dimension(10, 20));

        final javax.swing.GroupLayout mrModePanelLayout = new javax.swing.GroupLayout(
                mrModePanel);
        mrModePanel.setLayout(mrModePanelLayout);
        mrModePanelLayout
                .setHorizontalGroup(mrModePanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                mrModePanelLayout
                                        .createSequentialGroup()
                                        .addGap(35, 35, 35)
                                        .addGroup(
                                                mrModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                mrModeReqRecievedLabel)
                                                        .addComponent(
                                                                mrModeReqSentLabel))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                mrModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                mrModeDataSentTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                20,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                mrModeDataRecievedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                20,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(mrModeBtn,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 164,
                                javax.swing.GroupLayout.PREFERRED_SIZE));
        mrModePanelLayout
                .setVerticalGroup(mrModePanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                mrModePanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                mrModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                mrModeReqSentLabel)
                                                        .addComponent(
                                                                mrModeDataSentTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                Short.MAX_VALUE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                mrModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                mrModeDataRecievedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                Short.MAX_VALUE)
                                                        .addComponent(
                                                                mrModeReqRecievedLabel))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(mrModeBtn)));

        smModePanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        msBtn.setBackground(new java.awt.Color(0, 0, 255));
        msBtn.setText("Misson Start");
        msBtn.setEnabled(false);

        msModeReqSentLabel.setText("Send:");

        msModeDataSentTxtF.setBackground(new java.awt.Color(255, 0, 0));
        msModeDataSentTxtF.setEnabled(false);
        msModeDataSentTxtF.setPreferredSize(new java.awt.Dimension(10, 20));

        msModeReqRecievedLabel.setText("Receive:");

        msModeDataRecievedTxtF.setBackground(new java.awt.Color(255, 0, 0));
        msModeDataRecievedTxtF.setEnabled(false);
        msModeDataRecievedTxtF.setPreferredSize(new java.awt.Dimension(10, 20));

        final javax.swing.GroupLayout smModePanelLayout = new javax.swing.GroupLayout(
                smModePanel);
        smModePanel.setLayout(smModePanelLayout);
        smModePanelLayout
                .setHorizontalGroup(smModePanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                smModePanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                smModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(
                                                                smModePanelLayout
                                                                        .createSequentialGroup()
                                                                        .addContainerGap()
                                                                        .addComponent(
                                                                                msModeReqSentLabel)
                                                                        .addGap(31,
                                                                                31,
                                                                                31)
                                                                        .addComponent(
                                                                                msModeDataSentTxtF,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                20,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addGroup(
                                                                smModePanelLayout
                                                                        .createSequentialGroup()
                                                                        .addContainerGap()
                                                                        .addComponent(
                                                                                msModeReqRecievedLabel)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                        .addComponent(
                                                                                msModeDataRecievedTxtF,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                20,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addComponent(msBtn))
                                        .addContainerGap(42, Short.MAX_VALUE)));
        smModePanelLayout
                .setVerticalGroup(smModePanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                smModePanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                smModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                msModeReqSentLabel)
                                                        .addComponent(
                                                                msModeDataSentTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                smModePanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(
                                                                msModeReqRecievedLabel)
                                                        .addComponent(
                                                                msModeDataRecievedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(msBtn)));

        lmPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lmModeReqSentLabel.setText("Send:");

        lmModeDataSentTxtF.setBackground(new java.awt.Color(255, 0, 0));
        lmModeDataSentTxtF.setEnabled(false);
        lmModeDataSentTxtF.setPreferredSize(new java.awt.Dimension(10, 20));
        lmModeDataSentTxtF.setVerifyInputWhenFocusTarget(false);

        lmModeReqRecievedLabel.setText("Receive:");

        lmModeDataRecievedTxtF.setBackground(new java.awt.Color(255, 0, 0));
        lmModeDataRecievedTxtF.setEnabled(false);
        lmModeDataRecievedTxtF.setPreferredSize(new java.awt.Dimension(10, 20));
        lmModeDataRecievedTxtF.setVerifyInputWhenFocusTarget(false);

        lmBtn.setBackground(new java.awt.Color(255, 0, 0));
        lmBtn.setText("Landing Mode");
        lmBtn.setEnabled(false);

        final javax.swing.GroupLayout lmPanelLayout = new javax.swing.GroupLayout(
                lmPanel);
        lmPanel.setLayout(lmPanelLayout);
        lmPanelLayout
                .setHorizontalGroup(lmPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                lmPanelLayout
                                        .createSequentialGroup()
                                        .addGap(29, 29, 29)
                                        .addGroup(
                                                lmPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addGroup(
                                                                lmPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                lmModeReqSentLabel)
                                                                        .addGap(27,
                                                                                27,
                                                                                27))
                                                        .addGroup(
                                                                lmPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                lmModeReqRecievedLabel)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                        .addGroup(
                                                lmPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                lmModeDataSentTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                20,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                lmModeDataRecievedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                20,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addContainerGap())
                        .addGroup(
                                lmPanelLayout
                                        .createSequentialGroup()
                                        .addComponent(
                                                lmBtn,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)
                                        .addGap(34, 34, 34)));
        lmPanelLayout
                .setVerticalGroup(lmPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                lmPanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                lmPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                lmModeReqSentLabel)
                                                        .addComponent(
                                                                lmModeDataSentTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                lmPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                lmModeDataRecievedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                15,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                lmModeReqRecievedLabel))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lmBtn)));

        final javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(
                controlPanel);
        controlPanel.setLayout(controlPanelLayout);
        controlPanelLayout
                .setHorizontalGroup(controlPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                controlPanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                controlPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(
                                                                controlPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addContainerGap()
                                                                        .addComponent(
                                                                                rtfModePanel,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                168,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(30,
                                                                                30,
                                                                                30)
                                                                        .addComponent(
                                                                                mrModePanel,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(27,
                                                                                27,
                                                                                27)
                                                                        .addComponent(
                                                                                smModePanel,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(18,
                                                                                18,
                                                                                18)
                                                                        .addComponent(
                                                                                lmPanel,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                168,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addComponent(
                                                                controlLabel))
                                        .addContainerGap(
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)));

        controlPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
                new java.awt.Component[] { lmPanel, mrModePanel, rtfModePanel,
                        smModePanel });

        controlPanelLayout
                .setVerticalGroup(controlPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                controlPanelLayout
                                        .createSequentialGroup()
                                        .addComponent(controlLabel)
                                        .addGap(18, 18, 18)
                                        .addGroup(
                                                controlPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                controlPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addGroup(
                                                                                controlPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                                                false)
                                                                                        .addComponent(
                                                                                                rtfModePanel,
                                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                Short.MAX_VALUE)
                                                                                        .addComponent(
                                                                                                mrModePanel,
                                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                Short.MAX_VALUE))
                                                                        .addContainerGap())
                                                        .addGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                controlPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addGroup(
                                                                                controlPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                                                false)
                                                                                        .addComponent(
                                                                                                lmPanel,
                                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                Short.MAX_VALUE)
                                                                                        .addComponent(
                                                                                                smModePanel,
                                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                                Short.MAX_VALUE))
                                                                        .addContainerGap()))));

        connectionsPanel.setBorder(javax.swing.BorderFactory
                .createEtchedBorder());

        conLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        conLabel.setText("Connections");

        serialPTxtF.setEnabled(false);

        jLabel2.setText("Port:");

        baudTxtF.setEnabled(false);

        baudLabel.setText("Baud:");

        connectedTxtF.setBackground(new java.awt.Color(255, 0, 0));
        connectedTxtF.setEditable(false);
        connectedTxtF.setPreferredSize(new java.awt.Dimension(10, 20));

        connectedLabel.setText("Connected:");

        final javax.swing.GroupLayout connectionsPanelLayout = new javax.swing.GroupLayout(
                connectionsPanel);
        connectionsPanel.setLayout(connectionsPanelLayout);
        connectionsPanelLayout
                .setHorizontalGroup(connectionsPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                connectionsPanelLayout
                                        .createSequentialGroup()
                                        .addGroup(
                                                connectionsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(conLabel)
                                                        .addGroup(
                                                                connectionsPanelLayout
                                                                        .createSequentialGroup()
                                                                        .addGap(10,
                                                                                10,
                                                                                10)
                                                                        .addGroup(
                                                                                connectionsPanelLayout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                                false)
                                                                                        .addGroup(
                                                                                                connectionsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addComponent(
                                                                                                                jLabel2)
                                                                                                        .addPreferredGap(
                                                                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                                        .addComponent(
                                                                                                                serialPTxtF))
                                                                                        .addGroup(
                                                                                                connectionsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addComponent(
                                                                                                                baudLabel)
                                                                                                        .addPreferredGap(
                                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                        .addComponent(
                                                                                                                baudTxtF,
                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                88,
                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                                        .addGroup(
                                                                                                connectionsPanelLayout
                                                                                                        .createSequentialGroup()
                                                                                                        .addComponent(
                                                                                                                connectedLabel)
                                                                                                        .addGap(18,
                                                                                                                18,
                                                                                                                18)
                                                                                                        .addComponent(
                                                                                                                connectedTxtF,
                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                                20,
                                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                        .addContainerGap(28, Short.MAX_VALUE)));
        connectionsPanelLayout
                .setVerticalGroup(connectionsPanelLayout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                connectionsPanelLayout
                                        .createSequentialGroup()
                                        .addComponent(conLabel)
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                connectionsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                serialPTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jLabel2))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                connectionsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(baudLabel)
                                                        .addComponent(
                                                                baudTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(
                                                connectionsPanelLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                connectedLabel)
                                                        .addComponent(
                                                                connectedTxtF,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                10,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addContainerGap(
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)));

        exitBtn.setText("Exit");

        final javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                false)
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addComponent(
                                                                        controlPanel,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                .addComponent(
                                                                        connectionsPanel,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(
                                                                        exitBtn,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE))
                                                .addComponent(
                                                        telemetryPanel,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)));
        layout.setVerticalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addComponent(telemetryPanel,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        201,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(14, 14, 14)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(
                                                        layout.createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                false)
                                                                .addComponent(
                                                                        controlPanel,
                                                                        0,
                                                                        143,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(
                                                                        connectionsPanel,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE))
                                                .addComponent(exitBtn))
                                .addContainerGap()));
    }// </editor-fold>

    private void rtfModeBtnActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		
	}
    private void mrModeBtnActionPerformed(final java.awt.event.ActionEvent evt) {
        final JDialog mrModeFrame = new JDialog();
        final Container contentPane = mrModeFrame.getContentPane();
        contentPane.setLayout(new GridBagLayout());
        final GridBagConstraints c = new GridBagConstraints();

        c.gridx = 0;
        c.gridy = 0;
        final APHciMissionReadySwingPanel mrp = new APHciMissionReadySwingPanel();
        contentPane.add(mrp, c);

        c.gridy = 1;
        final JPanel panel = new JPanel();
        final JButton cancelBtn = new JButton("Cancel");
        cancelBtn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent arg0) {
                mrModeFrame.dispose();
            }
        });
        panel.add(cancelBtn);

        final JButton sendBtn = new JButton("Send");
        sendBtn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent arg0) {
                // Get GPS information for fly to instructions.
                final String way1Lat = mrp.getWay1LatTxtf().getText().trim();
                final String way1Long = mrp.getWay1LongTxtF().getText().trim();
                final String way1Alt = mrp.getWay1AltTxtF().getText().trim();
                final String way2Lat = mrp.getWay2LatTxtF().getText().trim();
                final String way2Long = mrp.getWay2LongTxtF().getText().trim();
                final String way2Alt = mrp.getWay2AltTxtF().getText().trim();
                final String way3Lat = mrp.getWay3LatTxtF().getText().trim();
                final String way3Long = mrp.getWay3LongTxtF().getText().trim();
                final String way3Alt = mrp.getWay3AltTxtF().getText().trim();

                final GpsPacket gpsPacketWay1 = new GpsPacket(3, Long
                        .parseLong(way1Long), Long.parseLong(way1Lat),
                        Long.parseLong(way1Alt), 0L, // ground speed
                        0L, // ground course
                        0, //numSats
                        0, // fix
                        0L, // time
                        0); // checksum
                final GpsPacket gpsPacketWay2 = new GpsPacket(3, Long
                        .parseLong(way2Lat), Long.parseLong(way2Long),
                        Long.parseLong(way2Alt), 0L, // ground speed
                        0L,
                        0,// ground course
                        0, // fix
                        0L, // time
                        0); // checksum
                final GpsPacket gpsPacketWay3 = new GpsPacket(3, Long
                        .parseLong(way3Lat), Long.parseLong(way3Long),
                        Long.parseLong(way3Alt), 0L, // ground speed
                        0L,
                        0,// ground course
                        0, // fix
                        0L, // time
                        0); // checksum

                logger.info("Waypoint One: " + gpsPacketWay1);
                logger.info("Waypoint Two: " + gpsPacketWay2);
                logger.info("Waypoint Three: " + gpsPacketWay3);

                // You need to sent the packet to the PacketBuilder and the
                // SerialPortManager to send.
                // Create a method in PacketUtils to create packet string that
                // you can send from an object
                // Not yet implemented.

                mrModeFrame.dispose();
            }
        });
        panel.add(sendBtn);
        panel.setSize(200, 200);

        contentPane.add(panel, c);
        mrModeFrame.setResizable(false);
        mrModeFrame.setModal(true);
        mrModeFrame.pack();
        mrModeFrame.setVisible(true);

    }

    // Variables declaration - do not modify
    private javax.swing.JLabel accelLabel;
    private javax.swing.JPanel accelPanel;
    private javax.swing.JLabel accelxLabel;
    private javax.swing.JTextField accelxTxtF;
    private javax.swing.JLabel accelyLabel;
    private javax.swing.JTextField accelyTxtF;
    private javax.swing.JLabel accelzLabel;
    private javax.swing.JTextField accelzTxtF;
    private javax.swing.JTextField altitudeTxtF;
    private javax.swing.JTextField axisxTxtF;
    private javax.swing.JLabel axisxLabel;
    private javax.swing.JTextField axisyTxtF;
    private javax.swing.JLabel axiszLabel;
    private javax.swing.JTextField axiszTxtF;
    private javax.swing.JLabel baudLabel;
    private javax.swing.JTextField baudTxtF;
    private javax.swing.JLabel conLabel;
    private javax.swing.JLabel connectedLabel;
    private javax.swing.JTextField connectedTxtF;
    private javax.swing.JPanel connectionsPanel;
    private javax.swing.JLabel controlLabel;
    private javax.swing.JPanel controlPanel;
    private javax.swing.JButton exitBtn;
    private javax.swing.JLabel gpsAltLabel;
    private javax.swing.JLabel gpsFixLabel;
    private javax.swing.JTextField gpsFixTxtF;
    private javax.swing.JLabel gpsGndCourseLabel;
    private javax.swing.JLabel gpsGndSpeedLabel;
    private javax.swing.JLabel gpsLabel;
    private javax.swing.JLabel gpsLatLabel;
    private javax.swing.JLabel gpsLongLabel;
    private javax.swing.JLabel gpsNumSatLabel;
    private javax.swing.JTextField gpsNumSatTxtF;
    private javax.swing.JPanel gpsPanel;
    private javax.swing.JLabel gpsTimeLabel;
    private javax.swing.JTextField gpsTimeTxtF;
    private javax.swing.JTextField grdCourseTxtF;
    private javax.swing.JTextField grdSpeedTxtF;
    private javax.swing.JLabel gyroLabel;
    private javax.swing.JPanel gyroPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField latTxtF;
    private javax.swing.JButton lmBtn;
    private javax.swing.JTextField lmModeDataRecievedTxtF;
    private javax.swing.JTextField lmModeDataSentTxtF;
    private javax.swing.JLabel lmModeReqRecievedLabel;
    private javax.swing.JLabel lmModeReqSentLabel;
    private javax.swing.JPanel lmPanel;
    private javax.swing.JTextField longTxtF;
    private javax.swing.JButton mrModeBtn;
    private javax.swing.JTextField mrModeDataRecievedTxtF;
    private javax.swing.JTextField mrModeDataSentTxtF;
    private javax.swing.JPanel mrModePanel;
    private javax.swing.JLabel mrModeReqRecievedLabel;
    private javax.swing.JLabel mrModeReqSentLabel;
    private javax.swing.JButton msBtn;
    private javax.swing.JTextField msModeDataRecievedTxtF;
    private javax.swing.JTextField msModeDataSentTxtF;
    private javax.swing.JLabel msModeReqRecievedLabel;
    private javax.swing.JLabel msModeReqSentLabel;
    private javax.swing.JButton rtfModeBtn;
    private javax.swing.JTextField rtfModeDataRecievedTxtF;
    private javax.swing.JTextField rtfModeDataSentTxtF;
    private javax.swing.JPanel rtfModePanel;
    private javax.swing.JLabel rtfModeReqRecievedLabel;
    private javax.swing.JLabel rtfModeReqSentLabel;
    private javax.swing.JTextField serialPTxtF;
    private javax.swing.JPanel smModePanel;
    private javax.swing.JLabel telemetryLabel;
    private javax.swing.JPanel telemetryPanel;

    // End of variables declaration

    /*
     * public void update(Observable o, TelemetryGyrosPacket x) {
     * logger.info("update1(" + o + "," + x + ");"); //String aX = x.toString();
     * //this.gyroXTxtF.setText(); String aX = String.valueOf(x.getGyroX());
     * String aY = String.valueOf(x.getGyroY()); String aZ =
     * String.valueOf(x.getGyroZ()); this.gyroXTxtF.setText(aX);
     * this.gyroYTxtF.setText(aY); this.gyroZTxtF.setText(aZ); //throw new
     * UnsupportedOperationException("Not supported yet."); }
     */
    @Override
    public void update(final Observable obs, final Object arg) {

        logger.info("update(" + obs + "," + arg + ");");
        if (arg instanceof TelemetryGyrosPacket) {
            tgp = (TelemetryGyrosPacket) arg;
            logger.info("update1(" + obs + "," + arg + ");");
            final String aX = Integer.toString(tgp.getGyroX());
            final String aY = Integer.toString(tgp.getGyroY());
            final String aZ = Integer.toString(tgp.getGyroZ());
            axisxTxtF.setText(aX);
            axisyTxtF.setText(aY);
            axiszTxtF.setText(aZ);

        } else if (arg instanceof TelemetryAccelsPacket) {
            tap = (TelemetryAccelsPacket) arg;
            logger.info("update2(" + obs + "," + arg + ");");
            final String accelX = Integer.toString(tap.getAccelX());
            final String accelY = Integer.toString(tap.getAccelX());
            final String accelZ = Integer.toString(tap.getAccelZ());
            accelxTxtF.setText(accelX);
            accelyTxtF.setText(accelY);
            accelzTxtF.setText(accelZ);
        } else if (arg instanceof RtfPacket) {
            logger.info("update3(" + obs + "," + arg + ");");

            if (((RtfPacket) arg).getRtfFlag() == 1) {
                rtfModeDataRecievedTxtF.setBackground(new java.awt.Color(0,
                        255, 0));
            }
            
        }else if(arg instanceof GpsPacket){
        	gpsPkt = (GpsPacket) arg;
        	logger.info("update3(" + obs + "," + arg + ");");
        	final String lat = Long.toString(gpsPkt.getLatitude());
        	final String lng = Long.toString(gpsPkt.getLongitude());
        	final String alt = Long.toString(gpsPkt.getAltitude());
        	final String gndSpeed = Long.toString(gpsPkt.getGroundSpeed());
        	final String gndCourse = Long.toString(gpsPkt.getGroundCourse());
        	final String numSats = Long.toString(gpsPkt.getNumSats());
        	final String fix = Long.toString(gpsPkt.getFix());
        	final String time = Long.toString(gpsPkt.getTime());
        	String utcTime = time.substring(0, 2) + ":" + time.substring(2,4) + ":" + time.substring(4,6);
        	this.latTxtF.setText(lat);
        	this.longTxtF.setText(lng);
        	this.altitudeTxtF.setText(alt);
        	this.grdSpeedTxtF.setText(gndSpeed);
        	this.grdCourseTxtF.setText(gndCourse);
        	this.gpsNumSatTxtF.setText(numSats);
        	this.gpsFixTxtF.setText(fix);
        	this.gpsTimeTxtF.setText(utcTime);
        	
        } else if (arg instanceof SerialPortStatus) {
            baudTxtF.setText(((SerialPortStatus) arg).getDataRate() + " ");
            serialPTxtF.setText(((SerialPortStatus) arg).getComPort());
            connectedTxtF.setBackground(new Color(0, 255, 0));

        }
        this.repaint();

    }
}
